package com.ztstkj.lzservices.utils

import android.content.Context
import android.speech.tts.TextToSpeech
import java.util.Locale

object SpeakUtil {
    private var textSpeech: TextToSpeech? = null
    fun speech(context: Context, text: String) {
        textSpeech = TextToSpeech(context) { status ->
            if (status == TextToSpeech.SUCCESS) {
                textSpeech?.language = Locale.CHINA
                textSpeech?.setPitch(2f)
                textSpeech?.setSpeechRate(1f)
                textSpeech?.speak(text, TextToSpeech.QUEUE_FLUSH, null, null)
            }
        }
    }
    fun shutdown(){
        textSpeech?.stop()
        textSpeech?.shutdown()
    }
}